#!/bin/sh

# build镜像文件
usage() {
	echo "Usage: sh build-images.sh"
	exit 1
}

tag=$1

# build images
echo "docker build images start ......"

docker build -f ./docker/gateway/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-gateway:${tag} .
docker build -f ./docker/admin/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-admin:${tag} .
docker build -f ./docker/customer/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-customer:${tag} .
docker build -f ./docker/auth/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-auth:${tag} .
docker build -f ./docker/api/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-api:${tag} .
docker build -f ./docker/sales/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-sales:${tag} .
echo "add marketing component"
docker build -f ./docker/marketing/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-marketing:${tag} .
echo "add bpmn component"
docker build -f ./docker/bpmn/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kmss-bpmn:${tag} .
docker build -f ./docker/settle/Dockerfile -t kcr.kmcloud.kingmed.idc/crm_dev/kingmed-settle:${tag} .



#删除无效的镜像
docker images -f "dangling=true" -q > /dev/null
if [ $? -eq 0 ] ;then
   echo "没有无效镜像"
else
   docker rmi $(docker images -f "dangling=true" -q)
fi
